<template>
  <div class="dashboard-container">
    <div>
      <div class="title">个人营业额</div>
      <div class="shouru" />
    </div>
    <div>
      <div class="title">个人营业额</div>
      <div class="shou" />
    </div>
    <div>
      <div class="title">个人营业额</div>
      <div class="shoue" />
    </div>
    <div>
      <div class="title">个人营业额</div>
      <div class="shouer" />
    </div>

  </div>
</template>

<script>
import { mapGetters } from 'vuex'
// import { get } from '@/api/user'
// import Mock from 'mockjs'
import * as echarts from 'echarts'
// import user from '@/store/modules/user'
import { date, getOrder } from '@/api/businessArea/share'

export default {
  name: 'Dashboard',

  date: {},
  computed: {
    ...mapGetters(['name'])
  },
  created() {
    this.getData()
  },
  mounted() {
    var shouruDom = document.querySelector('.shouru')
    var shouru = document.querySelector('.shou')
    var shourue = document.querySelector('.shoue')
    var shouruer = document.querySelector('.shouer')
    var youshouru = echarts.init(shouru)
    var youshourue = echarts.init(shourue)
    var youshouruer = echarts.init(shouruer)
    var myshouru = echarts.init(shouruDom)
    var bingzhuangtu = {
      tooltip: {
        trigger: 'item'
      },
      legend: {
        top: '5%',
        left: 'center'
      },
      series: [
        {
          name: '访问来源',
          type: 'pie',
          radius: ['40%', '70%'],
          avoidLabelOverlap: false,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#fff',
            borderWidth: 2
          },
          label: {
            show: false,
            position: 'center'
          },
          emphasis: {
            label: {
              show: true,
              fontSize: '40',
              fontWeight: 'bold'
            }
          },
          labelLine: {
            show: false
          },
          data: [
            { value: 1048, name: '搜索引擎' },
            { value: 735, name: '直接访问' },
            { value: 580, name: '邮件营销' },
            { value: 484, name: '联盟广告' },
            { value: 300, name: '视频广告' }
          ]
        }
      ]
    }
    var bingzhuangtu1 = {
      tooltip: {
        trigger: 'item'
      },
      legend: {
        top: '5%',
        left: 'center'
      },
      series: [
        {
          name: '访问来源',
          type: 'pie',
          radius: ['40%', '70%'],
          avoidLabelOverlap: false,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#fff',
            borderWidth: 2
          },
          label: {
            show: false,
            position: 'center'
          },
          emphasis: {
            label: {
              show: true,
              fontSize: '40',
              fontWeight: 'bold'
            }
          },
          labelLine: {
            show: false
          },
          data: [
            { value: 1048, name: '搜索引擎' },
            { value: 735, name: '直接访问' },
            { value: 580, name: '邮件营销' },
            { value: 484, name: '联盟广告' },
            { value: 300, name: '视频广告' }
          ]
        }
      ]
    }
    var myshouru_option1 = {
      xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [120, 200, 150, 80, 70, 110, 130],
          type: 'bar'
        }
      ]
    }
    var myshouru_option = {
      xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [120, 200, 150, 80, 70, 110, 130],
          type: 'bar'
        }
      ]
    }
    bingzhuangtu && youshouru.setOption(bingzhuangtu)
    bingzhuangtu1 && youshourue.setOption(bingzhuangtu1)
    myshouru_option && myshouru.setOption(myshouru_option)
    myshouru_option1 && youshouruer.setOption(myshouru_option1)
  },
  methods: {
    async getData() {
      const { data: data } = await date()
      // 订单列表数据
      const { data: ddd } = await getOrder()
      for (let i = 0; i < data.length; i++) {
        // 为每个商铺添加一个hyp对象用于保存销售额
        data[i].hyp = 0
        data[i].zzq = 0

        for (let j = 0; j < ddd.length; j++) {
          if (data[i].id === ddd[j].shop_id) {
            data[i].hyp += ddd[j].ordr_amt
            data[i].zzq += ddd[j].ordr_amt > 0 ? 1 : 0
          }
        }
      }
      console.log(data)
      console.log(5256464)
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-container {
  .shouru {
    width: 50%;
    height: 300px;
    float: left;
  }
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
  .shou {
    width: 50%;
    height: 300px;
    float: left;
  }
  .shoue {
    width: 50%;
    height: 300px;
    float: right;
  }
  .shouer {
    width: 50%;
    height: 300px;
    float: left;
  }
}
</style>
